/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package servidor;

import integracion.ControlAccion;
import integracion.ControlCliente;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


/**
 *
 * @author DaKaLu
 */
public class Servidor
{

    public static void main(String abc[]) {

        ArrayList<Thread> listaHilos = null;
        try
        {
            listaHilos = new ArrayList<Thread>();
            int port = 7870;
            ServerSocket escuchandoSocket = new ServerSocket(port);
            System.out.println("Servidor iniciado en puerto: " + port);
            while (true)
            {
                Socket socketCliente = escuchandoSocket.accept();
                Conexion hilo = new Conexion(socketCliente);
                listaHilos.add(hilo);
                new Conexion(socketCliente);
            }
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void enviarTodos()
    {

    }
}
class Conexion extends Thread {
	DataInputStream entrada = null;
	DataOutputStream salida = null;
    OutputStream outputSock = null;
	InputStream input;
    Socket socketCliente;
    boolean flag = true;


	public Conexion(Socket socketCliente) {
        try
        {
			this.socketCliente = socketCliente;
			entrada = new DataInputStream(socketCliente.getInputStream());
			salida = new DataOutputStream(socketCliente.getOutputStream());
            outputSock = socketCliente.getOutputStream();
            this.start();
		}
		catch (Exception e)
        {
			e.printStackTrace();
		}
	}

    public void enviarMensaje()
    {

    }
       
    @Override
    @SuppressWarnings("static-access")
	public void run()
    {

        ControlAccion miControl = new ControlAccion();
        ControlCliente miControlC = new ControlCliente();
        try
        {
            //while(flag)
            //{
                //miControl.traerAccion("YHOO");
                //miControl.crearAccion();
                //miControl.leer();
                //miControl.escribir();
                miControlC.leer();
                miControlC.escribir();
            //}
            outputSock.close();
            entrada.close();
            salida.close();
            socketCliente.close();
        }
        catch (Exception e)
        {
                e.printStackTrace();
        }
	}

}


